package sojo.com.inverter.task;

import lombok.extern.slf4j.Slf4j;
import sojo.com.inverter.modbus.ModbusClient;
import sojo.com.inverter.service.Device;
import sojo.com.inverter.service.DeviceProtocolService;

import java.util.Map;

/**
 * @author cheng_hu
 * @description:
 * @date 2023-02-22 15:54:27
 */
@Slf4j
public class ScheduledTask implements Runnable{

    private final String taskKey;
    private final ModbusClient modbusClient;
    private final Device device;
    private final Map<String, DeviceProtocolService> deviceProtocolServiceMap;

    public ScheduledTask(String taskKey,
                         ModbusClient modbusClient,
                         Device device,
                         Map<String, DeviceProtocolService> deviceProtocolServiceMap) {
        this.taskKey = taskKey;
        this.modbusClient = modbusClient;
        this.device = device;
        this.deviceProtocolServiceMap = deviceProtocolServiceMap;
    }

    @Override
    public void run() {
        DeviceProtocolService deviceProtocolService = deviceProtocolServiceMap.get(taskKey);
        log.info("定时器执行");
        deviceProtocolService.analysisData(modbusClient, device);
    }
}
